package com.mto.module.karaoke.portlet.util.comparator;

import com.liferay.portal.kernel.util.OrderByComparator;
import com.mto.module.karaoke.model.Song;

public class SongIdComparator extends OrderByComparator {

	private static final long serialVersionUID = -1523121635297308246L;
	public static final String ORDER_BY_ASC = "songId ASC";
	public static final String ORDER_BY_DESC = "songId DESC";
	public static final String[] ORDER_BY_FIELDS = { "songId" };

	public SongIdComparator() {
		this(false);
	}

	public SongIdComparator(boolean ascending) {
		_ascending = ascending;
	}

	@Override
	public int compare(Object obj1, Object obj2) {
		Song song1 = (Song) obj1;
		Song song2 = (Song) obj2;
		int value = Long.valueOf(song1.getSongId()).compareTo(Long.valueOf(song2.getSongId()));
		if (_ascending) {
			return value;
		} else {
			return -value;
		}
	}

	@Override
	public String getOrderBy() {
		if (_ascending) {
			return ORDER_BY_ASC;
		} else {
			return ORDER_BY_DESC;
		}
	}

	@Override
	public String[] getOrderByFields() {
		return ORDER_BY_FIELDS;
	}

	@Override
	public boolean isAscending() {
		return _ascending;
	}

	private boolean _ascending;
}
